package com.assignwork.dto;

import com.assignwork.entity.AssignWork;
import com.assignwork.entity.AssignWorkInfo;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import io.swagger.annotations.ApiModel;
import lombok.Data;
import org.springblade.core.tool.utils.Func;

import java.util.ArrayList;
import java.util.List;

/**
 * 二级配工(AssignWork)DTO
 * @since 2024-01-31 09:49:02
 */
@Data
@ApiModel(value = "AssignWorkDTO", description = "二级配工")
public class AssignWorkDTO extends AssignWork  {

    private List<AssignWorkInfoDTO> workInfo;
    @JsonSerialize(using = ToStringSerializer.class)
    private Long teamId;

    @JsonSerialize(using = ToStringSerializer.class)
    private Long workerCorp;
    @JsonSerialize(using = ToStringSerializer.class)
    private Long machineCorp;

    public List<AssignWorkInfo> getWorkInfoEtt() {
        List<AssignWorkInfo> res = new ArrayList<>();
        if (Func.isNotEmpty(workInfo) && getId() != null) {
            for (AssignWorkInfoDTO dto : workInfo) {
                if (dto.getId() != null && dto.getId() == -1L) {
                    dto.setId(null);
                }
                dto.setAssignWorkId(getId());
                dto.setStatus(1);
                res.add(dto);
            }
        }
        return res;
    }
}

